package com.example.ordersystem;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;



import androidx.appcompat.app.AppCompatActivity;

import com.example.ordersystem.pojo.Order;
import com.example.ordersystem.utils.ListDataSave;
import com.example.ordersystem.utils.MyDBOpenHelper;
import com.example.ordersystem.utils.OldOrderAdapter;

import java.util.ArrayList;
import java.util.List;

//历史订单
public class OldOrderActivity extends AppCompatActivity {
    private List<Order> list = new ArrayList<>();

    MyDBOpenHelper myDBOpenHelper = new MyDBOpenHelper(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.old_food_order);
        SQLiteDatabase db = myDBOpenHelper.getReadableDatabase();
        ArrayList<Order> query = myDBOpenHelper.query(db, ListDataSave.getUserLogin(this));

        list = query;
        final OldOrderAdapter oldOrderAdapter = new OldOrderAdapter(this, R.layout.old_order_food, list);
        ListView listView = findViewById(R.id.old_order_list_view);

        listView.setAdapter(oldOrderAdapter);

        ImageView order_to_home = findViewById(R.id.order_to_home);
        order_to_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OldOrderActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });
    }
}


